/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.system.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.system.entity.Dept;
import org.springblade.modules.system.vo.*;

import java.util.List;
import java.util.Map;

/**
 * Mapper 接口
 *
 * @author Chill
 */
public interface DeptMapper extends BaseMapper<Dept> {

	/**
	 * 懒加载部门列表
	 *
	 * @param tenantId
	 * @param parentId
	 * @param param
	 * @return
	 */
	List<DeptVO> lazyList(String tenantId, Long parentId, Map<String, Object> param);

	/**
	 * 获取树形节点
	 *
	 * @param tenantId 租户
	 * @isSign 是否只要考勤人员租，默认不需要
	 * @return 数据集
	 */
	List<DeptVO> tree(@Param("tenantId") String tenantId,@Param("isSign") Boolean isSign,@Param("signSetingId") String signSetingId);

	/**
	 * 懒加载获取树形节点
	 *
	 * @param tenantId
	 * @param parentId
	 * @return
	 */
	List<DeptVO> lazyTree(String tenantId, Long parentId);

	/**
	 * 获取部门名
	 *
	 * @param ids
	 * @return
	 */
	List<String> getDeptNames(Long[] ids);

	/**
	 * 根据部门集合查询用户数
	 * @param ids
	 * @return
	 */
    Integer selectUserCountBydeptIds(String ids);

	/**
	 * 懒加载获取部门及部门人员数(部门统计人数，人员统计保养任务数)
	 * @param tenantId
	 * @param deptId
	 * @param level
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<DeptMemberVO> deptMemberAmountTree(@Param("tenantId") String tenantId, @Param("deptId") Long deptId,@Param("level") Integer level);

	/**
	 * 获取部门人员列表（包含人员维保涉及梯数）
	 * @param deptId
	 * @param status
	 * @return
	 */
	List<UserTaskAmountVO> getDeptUsers(@Param("deptId") Long deptId, @Param("status") Integer status);

	/**
	 * 获取部门及任务计划数树形结构
	 * @param tenantId
	 * @param yearMonth 年月
	 * @return
	 */
	List<DeptVO> deptPlanTree(@Param("tenantId") String tenantId,  @Param("yearMonth") String yearMonth);

	/**
	 * 根据用户id获取部门祖级列表
	 * @param userIds
	 * @return
	 */
	List<UserAncestorsVO> getAncestorsByUserIds(List<Long> userIds);

	/**
	 * 根据用户id获取部门祖级列表
	 * @param userId
	 * @return
	 */
	List<String> getAncestorsByUserId(Long userId);

    List<Dept> getDeptByParentName(String deptName);

	/**
	 * 根据id 统计部门电梯关联关系数量
	 * @param ids 参数id
	 * @return 关联关系数量
	 */
	Integer selectRelationCountByDeptIds(String ids);

	/**
	 * 根据id 查询该部门关联的电梯数量
	 * @param ids 参数id
	 * @return 关联电梯数量
	 */
	Integer selectElevatorCountByIds(List<Long> ids);

	/**
	 * 获取当前租户下组织结构包括人员
	 * @return 数据集
	 * @param tenantId
	 * @param status
	 */
    List<DeptStatisticalVO> deptMaintenanceStatisticalTree(@Param("tenantId") String tenantId,@Param("status")  Integer status);

	List<Dept> listByIdsOrderByIds(@Param("ancestorsIds") List<Long> ancestorsIds);

	/**
	 * 获取部门及部门人员数(部门统计人数，人员统计保养任务数)
	 * @param tenantId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<DeptUserMemberVO> deptUserMemberAmountTree(@Param("tenantId") String tenantId);

	List<DeptVO> lazyListV2(String tenantId,Long parentId,Map<String, Object> param,String signSetingId);

    List<Long> selectDeptAndAllChildIds(List<Long> deptIds);

    List<Dept> selectDeptAndAllChildDepts(List<Long> deptIds);
}
